// pages/find/card/my-card.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    onShow() {
        this.loadCard();
    },
    loadCard: function () {
        app.http.get("member-visiting-card/card-info").then(res => {
            try {
                this.setData({
                    info: res.data.info.memberVisitingCard,
                    images: res.data.info.memberVisitingCard.image,
                    keep_num: res.data.keep_num,
                    like_num: res.data.like_num,
                });
            } catch (err) {
                wx.showModal({
                    title: '提示',
                    content: '您还没有创建名片',
                    confirmText: "立即创建",
                    success: res => {
                        if (res.confirm) {
                            wx.navigateTo({
                                url: './create-card',
                            })
                        } else {
                            wx.navigateBack({

                            })
                        }
                    }
                })
            }
            app.checkShare(this.data)
        }).catch(err => {
            app.wxToast.error(err.message);
        })
    },
    /**
     * 我的名片夹
     */
    cardList: function () {
        wx.navigateTo({
            url: 'card-list'
        })
    },
    /**
     * 编辑名片
     */
    updateCard: function () {
        wx.navigateTo({
            url: 'create-card?id=' + this.data.info.id
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        const id = wx.getStorageSync("mid")
        return {
            title: "您好!这是我的名片,请惠存",
            path: "/pages/personal/card/other-card?id=" + id + "&shareId=" + id
        }
    },
})